/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package CONTABILIDAD_CONTROLADOR;

import CONTABILIDAD_MODELO.CON_DATOS_EMPRESA;
import Conexion.Conexion;
import RRHH_Modelo.RHH_USUARIO;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author equipo_4
 */
@WebServlet(name = "CON_DATOS_EMPRESA_CONTROLLER", urlPatterns = {"/CON_DATOS_EMPRESA_CONTROLLER"})
public class CON_DATOS_EMPRESA_CONTROLLER extends HttpServlet {

    /**
     * Processes requests for both HTTP
     * <code>GET</code> and
     * <code>POST</code> methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException, SQLException, ParseException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
            RHH_USUARIO usuario = ((RHH_USUARIO)request.getSession().getAttribute("usr"));
            Conexion con = new Conexion(usuario.getUSUARIO(), usuario.getPASSWORD());
            
            
            CON_DATOS_EMPRESA datos = new CON_DATOS_EMPRESA(con);
            datos=datos.Todos().get(0);
            String nit = request.getParameter("nit");
            String razsoc = request.getParameter("razsoc");
            String ncomercio = request.getParameter("ncomercio");
            String ccuentabanco = request.getParameter("ccuentabanco");
            String cbanco = request.getParameter("cbanco");
            String fundacion = request.getParameter("fundacion");
            String constitucion = request.getParameter("constitucion");
            String fundaempresa = request.getParameter("fundaempresa");
            String aeco = request.getParameter("aeco");
            
            datos.setNIT(nit);
            datos.setNRO_COMERCIO(ncomercio);
            datos.setRAZON_SOCIAL(razsoc);
            datos.setCODIGO_CUENTA_BANCO(ccuentabanco);
            datos.setCUENTA_BANCO(cbanco);
            SimpleDateFormat df= new SimpleDateFormat("dd/MM/yyyy");
            datos.setFUNDACION(df.parse(fundacion));
            datos.setCONSTITUCION(constitucion);
            datos.setFUNDEMPRESA(fundaempresa);
            datos.setACTIVIDAD_ECONOMICA(aeco);
            
            datos.Modificar1();
            con.Close();
            response.sendRedirect("CONTABILIDAD/CON_DATOS_EMPRESA.jsp");
            
        } finally {            
            out.close();
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP
     * <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        try {
            processRequest(request, response);
        } catch (SQLException ex) {
            Logger.getLogger(CON_DATOS_EMPRESA_CONTROLLER.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ParseException ex) {
            Logger.getLogger(CON_DATOS_EMPRESA_CONTROLLER.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /**
     * Handles the HTTP
     * <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        try {
            processRequest(request, response);
        } catch (SQLException ex) {
            Logger.getLogger(CON_DATOS_EMPRESA_CONTROLLER.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ParseException ex) {
            Logger.getLogger(CON_DATOS_EMPRESA_CONTROLLER.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
